﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppManage.Data.Functions;

namespace AppManage.EntityFramework.Mapping
{
    public class FunctionMap : EntityTypeConfiguration<Function>
    {
        public FunctionMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.FunctionName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Action)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Description)
                .HasMaxLength(200);

            this.Property(t => t.DisplayName)
                .HasMaxLength(100);

            this.Property(t => t.Icon)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Functions");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.FunctionName).HasColumnName("FunctionName");
            this.Property(t => t.ModuleId).HasColumnName("ModuleId");
            this.Property(t => t.Action).HasColumnName("FunctionAction");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.IsActive).HasColumnName("IsActive");
            this.Property(t => t.DisplayName).HasColumnName("FunctionDisplayName");
            this.Property(t => t.Icon).HasColumnName("Icon");
            this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
            this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
            this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");
            this.Property(t => t.ModifiedOn).HasColumnName("ModifiedOn");

            //Relateships
            this.HasOptional(t => t.Module)
                .WithMany(t => t.Functions)
                .HasForeignKey(t => t.ModuleId);
        }
    }
}
